<template>
	<view>
		<view class="banmi_flex a-c p-10">
			<view class="banmi_input_name">公众号名称:</view>
			<view class="banmi_input_view">
				<uni-easyinput v-model="find.name" placeholder="填写公众号名称">
				</uni-easyinput>
			</view>
		</view>
		<view class="banmi_flex a-c p-10">
			<view class="banmi_input_name">AppId:</view>
			<view class="banmi_input_view">
				<uni-easyinput v-model="find.apppid" placeholder="填写公众号appid">
				</uni-easyinput>
			</view>
		</view>
		<view class="banmi_flex a-c p-10">
			<view class="banmi_input_name">AppSecret:</view>
			<view class="banmi_input_view">
				<uni-easyinput v-model="find.AppSecret" placeholder="填写公众号AppSecret">
				</uni-easyinput>
			</view>
		</view>
		<view class="p-10">
			<text class="f30">微信公众号推送通信</text>
		</view>
		<view class="banmi_flex a-c p-10" style="justify-content: flex-start;flex-wrap: wrap;">
			<view class="banmi_input_name">IP白名单:</view>
			<view class="banmi_input_view">
				<uni-easyinput @click="on_set_copy(find.ip)" disabled :placeholder="find.ip">
				</uni-easyinput>
			</view>

			<view class="m-l-10">
				<button @click="on_set_copy(find.ip)" type="primary" size="mini">一键复制</button>
			</view>
		</view>
		<view class="banmi_flex a-c p-10" style="justify-content: flex-start;flex-wrap: wrap;">
			<view class="banmi_input_name">URL(服务器地址):</view>
			<view class="banmi_input_view">
				<uni-easyinput disabled v-model="find.weixin_account_url">
				</uni-easyinput>
			</view>

			<view class="m-l-10">
				<button @click="on_set_copy(find.weixin_account_url)" type="primary" size="mini">一键复制</button>
			</view>
		</view>
		<view class="banmi_flex a-c p-10" style="justify-content: flex-start;flex-wrap: wrap;">
			<view class="banmi_input_name">Token(令牌):</view>
			<view class="banmi_input_view">
				<uni-easyinput placeholder="请填写token" v-model="find.wx_token">
				</uni-easyinput>
			</view>

			<view class="m-l-10">
				<button @click="on_set_copy(find.wx_token)" type="primary" size="mini">一键复制</button>
			</view>
			<view class="m-l-10">
				<button @click="on_set_token()" type="primary" size="mini">随机token</button>
			</view>
		</view>
		<view class="banmi_flex a-c p-10" style="justify-content: flex-start;flex-wrap: wrap;">
			<view class="banmi_input_name">EncodingAESKey(消息加解密密钥):</view>
			<view class="banmi_input_view">
				<uni-easyinput placeholder="请填写encodingAESKey" v-model="find.encodingAESKey">
				</uni-easyinput>
			</view>
			<view class="m-l-10">
				<button @click="on_set_copy(find.encodingAESKey)" type="primary" size="mini">一键复制</button>
			</view>
			<view class="m-l-10">
				<button @click="on_set_key()" type="primary" size="mini">随机key</button>
			</view>
		</view>
		<view class="banmi_flex a-c p-10 bb">
			<view class="banmi_input_name">加密方式:</view>
			<view class="banmi_input_view">
				<text>明文模式（暂时只支持明文模式）</text>
			</view>
		</view>
		<view class="" style="height: 40px;">
		</view>
		<view @click="on_save" class="f30 banmi_flex a-c j-c b_y cff ml3"
			style="background-color: #1E90FF;width: 50%;height: 40px;border-radius: 10px;margin-left: 20px;">
			保存
		</view>
		<view class="p-10">
			<text class="f34 cred w800">以下是图文教程</text>
		</view>
		<view class="">
			<image src="@/static/1.png" style="width: 90%;" mode="widthFix"></image>
		</view>
		<view class="">
			<image src="@/static/2.png" style="width: 90%;" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				find: {}
			};
		},
		mounted() {
			this.init();
		},
		methods: {
			async on_save() {
				uni.showLoading({
					title: '正在保存中',
					mask: true,
				})
				var that = this;
				const ret = await this.Banmikeji.DeveloperWechats_save(this.find);
				uni.hideLoading()
				if (ret.status != 200) {
					uni.showModal({
						title: '提示',
						content: ret.msg,
						showCancel: false,
						success: function(res) {

						}
					});
					return
				}
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})
				that.init();
			},
			on_set_copy(url) {
				uni.setClipboardData({
					data: url,
					success: function() {

					}
				});
			},
			async on_set_token() {
				const ret = await this.Banmikeji.DeveloperWechats_weixin_set_token({});
				uni.showToast({
					title: ret.msg,
					icon: "none"
				})
				this.find.wx_token = ret.data;
			},
			async on_set_key() {
				const ret = await this.Banmikeji.DeveloperWechats_weixin_set_key({});
				uni.showToast({
					title: ret.msg,
					icon: "none"
				})
				this.find.encodingAESKey = ret.data;
			},
			async init() {
				let requestParams = {
					id: 1,
				};
				const ret = await this.Banmikeji.DeveloperWechats_index(requestParams);
				this.find = ret.data;
				this.apppid = ret.data.apppid;
				this.AppSecret = ret.data.AppSecret;
				this.vname = ret.data.name;
				var url = this.find.weixin_account_url;
				if (url.indexOf("https") != -1) {
					return
				}
				// uni.showModal({
				// 	title: '提示',
				// 	content: '域名需要https才可使用本功能',
				// 	showCancel: false,
				// 	success: function(res) {
				// 		if (res.confirm) {
				// 			uni.navigateBack()
				// 		}
				// 	}
				// });


			},
		}
	}
</script>

<style lang="scss">

</style>